package com.warehouse.controller;

import com.warehouse.dto.*;
import com.warehouse.entity.ProType;
import com.warehouse.entity.Warehouse;
import com.warehouse.service.ProTypeService;
import com.warehouse.service.ProductService;
import com.warehouse.service.WarehouseService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 仓库后台
 */
@CrossOrigin//处理跨域问题
@Slf4j
@Api(tags = "仓库管理")
@RestController
@RequestMapping("/api/ware")
public class WareController {

    //注入
    @Autowired
    private WarehouseService warehouseService;
    //注入商品的service层
    @Autowired
    private ProductService productService;

    //注入产品类型层
    @Autowired
    private ProTypeService proTypeService;


    /**
     * 产看仓库所有信息:Echar用的数据
     */
    @ApiOperation(value = "仓库的信息",httpMethod = "GET")
    @RequestMapping(value = "/wareInfo",method = RequestMethod.GET)
    public Result wareInfo(){
        List<Warehouse> list=warehouseService.findwareInfo();
        List<WareInfo> li=new ArrayList<WareInfo>();
        for(Warehouse ware:list){
          WareInfo wareInfo= warehouseService.wareInfo(ware.getId());
         li.add(wareInfo);
        }
       return new Result(ResultCode.SUCCESS,li);
    }
    /**
     * 查询产品的类型
     */
    @ApiOperation(value = "产品类型的信息",httpMethod = "GET")
    @RequestMapping(value = "/findProTyoeInfo",method = RequestMethod.GET)
    public Result findProTyoeInfo(){
        List<ProType> list=proTypeService.findProTyoeInfo();
        return new Result(ResultCode.SUCCESS,list);
    }

    /***
     * 查询要入库的 :入库管理 以及模糊查询
     */
    @ApiOperation(value = "查询没有入库的产品",httpMethod = "GET")

    @RequestMapping(value = "/wareall",method = RequestMethod.GET)
    public Result selcetInware(@RequestParam(required = false) String proId,@RequestParam(required = false)String proName,
                               @RequestParam(required = false)String supId,@RequestParam(required = false)String wareId){
        List<Warehousing> list= productService.selectLikePro(wareId,supId,proId,proName);
        for (Warehousing warehouse1:list){
            System.out.println(warehouse1);
        }
      if (list!=null){
          return new Result(ResultCode.SUCCESS,list);
      }
        System.out.println("=========================");
     Result result= new Result();
      result.setMessage("暂时没有要入库的");
     return result ;

    }

    /**
     * 对商品进行入库
     */
    @ApiOperation(value = "对商品进行入库",httpMethod = "GET")
    @RequestMapping(value = "/inware",method = RequestMethod.GET)
    public Result inWarePro(String id){
        System.out.println(id);
        boolean b=productService.inWarePro(id);
        if (b){
            return new Result(ResultCode.SUCCESS);
        }
        return new Result(ResultCode.FAIL);
    }

    /**
     * 查询所有出库的 :出库管理
     */
    @ApiOperation(value = "查询所有出库的产品",httpMethod = "GET")
    @RequestMapping(value = "/outware",method = RequestMethod.GET)
    public Result selectOutWare(@RequestParam(required = false) String proId,@RequestParam(required = false)String proName,
                                @RequestParam(required = false)String supId,@RequestParam(required = false)String wareId){
        System.out.println(proId);
        List<Warehousing> list=productService.selectOutWare(wareId,supId,proId,proName);
       log.info(list.toString());
        if (list!=null){
            return new Result(ResultCode.SUCCESS,list);
        }
        Result result= new Result();
        result.setMessage("暂时没有要出库的");
        return result ;
    }
    /**
     * 对商品进行出库
     */
    @ApiOperation(value = "对商品进行出库",httpMethod = "GET")
    @RequestMapping(value = "/outWarePro",method = RequestMethod.GET)
    public Result outWarePro( String id){
        System.out.println(id);
        boolean b=productService.outWarePro(id);
        if (b){
            return new Result(ResultCode.SUCCESS);
        }
        return new Result(ResultCode.FAIL);
    }
}
